package org.wanho.servlet;

import com.alibaba.fastjson.JSON;
import org.wanho.entity.User;
import org.wanho.util.ResponseResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-05-04 15:50
 * Description：<描述>
 */
@WebServlet("/findAllUsers")
public class UserServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<User> list = new ArrayList<>();
        list.add(new User(101,"周易",20, new Date()));
        list.add(new User(102,"周一",24, new Date()));
        list.add(new User(201,"周二",18, new Date()));
        list.add(new User(202,"周三",22, new Date()));
        list.add(new User(304,"周四",20, new Date()));

        resp.setContentType("application/json;charset=utf8");
        PrintWriter out = resp.getWriter();
        out.print(JSON.toJSONString(ResponseResult.success(list)));
        out.close();
    }
}
